package com.mk.controller.user;

import com.mk.dto.PetDTO;
import com.mk.entity.Pet;
import com.mk.result.Result;
import com.mk.service.IPetService;
import com.mk.vo.PetInfoVO;
import com.mk.vo.PetNumberPlateVO;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDateTime;
import java.util.List;

/**
 * 小程序宠物业务
 */
@RestController("userPetController")
@RequestMapping("/user/pet")
@RequiredArgsConstructor
public class PetController {

    private final IPetService petService;

    /**
     * 根据号牌二维码获取宠物信息
     * @param numberPlate
     * @return
     */
    @CrossOrigin
    @GetMapping
    public Result<PetNumberPlateVO> getByNumberPlate(String numberPlate) {
        Pet pet = petService.getByNumberPlate(numberPlate);
        PetNumberPlateVO petNumberPlateVO = new PetNumberPlateVO();
        BeanUtils.copyProperties(pet, petNumberPlateVO);
        return Result.success(petNumberPlateVO);
    }

    /**
     * 根据宠物id获得宠物信息
     * @param id
     * @return
     */
    @CrossOrigin
    @GetMapping("/id")
    public Result<PetInfoVO> getById(Long id) {
        Pet pet = petService.getById(id);
        PetInfoVO petInfoVO = new PetInfoVO();
        BeanUtils.copyProperties(pet, petInfoVO);
        return Result.success(petInfoVO);
    }

    //备案宠物信息 TODO
    @PostMapping
    public Result registration(@RequestBody Pet pet) {

        return Result.success();
    }

    /**
     * 添加宠物
     * @param petDTO
     * @return
     */
    @CrossOrigin
    @PostMapping("/save")
    public Result save(@RequestBody PetDTO petDTO) {
        Pet pet = new Pet();
        BeanUtils.copyProperties(petDTO, pet);
        petService.add(pet);
        return Result.success();
    }

    //TODO UI界面的更换宠物需要细节进行编写
    @GetMapping("/query")
    public Result<List<PetNumberPlateVO>> query() {
        return Result.success();
    }
}
